import { defineStore } from "pinia";

export const useUserStore = defineStore("user", {
  state: () => {
    return {
      username: localStorage.getItem("username") || "",
      token: localStorage.getItem("token") || "",
      userid: localStorage.getItem("userid") || "",
    };
  },
  getters: {},
  actions: {
    setUserName(payload) {
      this.username = payload;
      localStorage.setItem("username", payload);
    },
    setToken(payload) {
      this.token = payload;
      localStorage.setItem("token", payload);
    },
    setUserId(payload) {
      this.userid = payload;
      localStorage.setItem("userid", payload);
    },
    removeUserInfo() {
      this.username = "";
      this.token = "";
      this.userid = "";
      localStorage.removeItem("username");
      localStorage.removeItem("token");
      localStorage.removeItem("userid");
    },
  },
});


export const useCartStore = defineStore('cart', {
  state: () => {
    return {
      cardList: [
        {
          tltle: "纸巾",
          need: false,
        },
        {
          tltle: "奶包",
          need: false,
        },
        {
          tltle: "糖包",
          need: false,
        },
      ]
    }
  }
})


export const useAddressStore = defineStore('address', {
  state: () => {
    return {
      addressinfo:JSON.parse(localStorage.getItem('setaddress'))  ||  {}
    }
  },
  getters: {

  },
  actions: {
    setAddress(payload) {
      // this.addressinfo = ''
      this.addressinfo = payload
      localStorage.setItem('setaddress', JSON.stringify(payload))

    }

  }
})
